package dht.simulation;

public class VNodeV2 implements Cloneable {
	public int id;
	public int serverId;
	public double startTime;
	public double lastReportTime;
	public int readCounter;
	public int writeCounter;

	// public Vector<Double> readHistory;
	// public Vector<Double> writeHistory;

	public VNodeV2(int id, int serverId, double startTime) {
		// readHistory = new Vector<Double>();
		// writeHistory = new Vector<Double>();
		this.id = id;
		this.serverId = serverId;
		this.startTime = startTime;
		this.lastReportTime = startTime;
		this.readCounter = 0;
		this.writeCounter = 0;
	}

	public double getLoad() {
		if (lastReportTime - startTime >= GlobalVariables.loadMeasureInterval) {
			return (readCounter * GlobalVariables.readLoadWeight + writeCounter
					* GlobalVariables.writeLoadWeight)
					/ (lastReportTime - startTime);
		}
		return 0.0;
	}

	public synchronized Object clone() {
		try {
			return super.clone();
		} catch (CloneNotSupportedException e) {
			throw new InternalError();
		}
	}

}
